package com.mg.admin.service.admin.impl;

import com.mg.admin.bean.admin.WxMenuVO;
import com.mg.admin.bean.admin.WxSetVO;
import com.mg.admin.dao.admin.WxMenuMapper;
import com.mg.admin.dao.admin.WxSetMapper;
import com.mg.admin.service.admin.WxMenuService;
import com.mg.admin.service.admin.WxSetService;
import com.xiaoleilu.hutool.crypto.SecureUtil;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpMenuService;
import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
import me.chanjar.weixin.mp.bean.menu.WxMpMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by jujunchen on 2017/9/24.
 */
@Service
public class WxMenuServiceImpl implements WxMenuService,WxMpMenuService{

    @Autowired
    private WxMenuMapper wxMenuMapper;


    @Override
    public List<WxMenuVO> findAll(Integer status) {
        List<WxMenuVO>  list = wxMenuMapper.findAll(status);
        return list;
    }

    @Override
    public void insertOne(WxMenuVO wxMenuVO) {
        if (wxMenuVO.getType().equalsIgnoreCase("click")){
            wxMenuVO.setKeyCode(SecureUtil.md5(wxMenuVO.getName()+wxMenuVO.getOrders()));
        }
        wxMenuMapper.insertOne(wxMenuVO);
    }

    @Override
    public void updateOne(WxMenuVO wxMenuVO) {
        if (wxMenuVO.getType().equalsIgnoreCase("click")){
            wxMenuVO.setKeyCode(SecureUtil.md5(wxMenuVO.getName()+wxMenuVO.getOrders()));
        }
        wxMenuMapper.updateOne(wxMenuVO);
    }

    @Override
    public void delete(Long id) {
        WxMenuVO wxMenuVO = wxMenuMapper.findOneById(id);
        wxMenuMapper.delete(wxMenuVO.getOrders());
    }

    @Override
    public WxMenuVO findOneById(Long id) {
        WxMenuVO wxMenuVO = wxMenuMapper.findOneById(id);
        return wxMenuVO;
    }

    @Override
    public String menuCreate(WxMenu wxMenu) throws WxErrorException {
        return null;
    }

    @Override
    public String menuCreate(String s) throws WxErrorException {
        return null;
    }

    @Override
    public void menuDelete() throws WxErrorException {

    }

    @Override
    public void menuDelete(String s) throws WxErrorException {

    }

    @Override
    public WxMpMenu menuGet() throws WxErrorException {
        return null;
    }

    @Override
    public WxMenu menuTryMatch(String s) throws WxErrorException {
        return null;
    }

    @Override
    public WxMpGetSelfMenuInfoResult getSelfMenuInfo() throws WxErrorException {
        return null;
    }


}
